<?php
/**
 * @page map_module Map %Module
 * 
 * This module allows you to place Geo-maps with various listings as pointers, anywhere on the site.
 * <b>1. You can set you own criteria for which listings to show on the map</b>
 * As an example you can see how we have displayed Popular 5 restaurants on home page on our demo - http://yelpclone.demos.crowdvox.com/
 * To create this module we created a content scope for popular restaurants first and then selected the "popular restaurant" as our filter for map module. 
 * @image html popular_restaurant.png

 * <b>2. You can see the map module to show listings on map of a page automatically</b>
 * As an example you can see the restaurant category page of our yelp demo- http://yelpclone.demos.crowdvox.com/listings/index/category/category:Restaurants/
 * To create this module, in parameters tab of map module select content type- autodetect and in visibility tab select category page. You can similarly show map on search result pages too.  
 * @image html Category_Restaurants.png
 */
	class MapModule extends GigaModule
	{
		var $name = "Map Module";
		
		var $configuration = null;
		function __construct()
		{
			$this->configuration = array(
			'model' => array(
			'type' => 'select',
			'empty' => __('Autodetect'),
			'group' => 'add',
			'label' => __('Content Type'),
			'class'=>"scope_model_select",
			'options' => array('Listing'=>__('Using condition')),
			'triggers' => array('onChange' => array('update' => 'scope', 'from_model' => 'Content')),
			),

		'scope' => array(
			'type' => 'select',
			'empty' => __('-Select-'),
			'group' => 'add',
			'label' => __("Filter")."&nbsp;&nbsp;&nbsp;(<a href=\"javascript:void(0);\" class=\"addNewScope\" onclick=\"addScope(this)\">".__("Define new")."</a>)",
			),
		'limit'=>array(
			'type'=>"text",
			'label'=>"Number of records to be shown",
			'after'=>__("Will be used if using filter."),
			'group'=>"add",
			'default'=>5,

			),
			'height'=>array("type"=>"text","after"=>__("Only in pixels. Enter like '150px'."),"validate"=>VALID_NOT_EMPTY,'default'=>'150px'),
			'width'=>array("type"=>"text","after"=>__("Only in pixels. Enter like '200px'."),"validate"=>VALID_NOT_EMPTY,'default'=>'200px'),
			'follow_user'=>array('label'=>"Should map follow the user?",'options'=>array(__("No"),__("Yes")))
			);
		}
		function render($params)
		{
			extract($params);
			$viewObj = ClassRegistry::getObject('view');
			$options = compact("height","width","follow_user");
			$detectType = "auto";
			if($params['model'] == "Listing")
			{
				if(!isset($limit) || !$limit)
				{
					$limit = $this->configuration['limit']['default'];
				}
				$paramsForScope = compact('model','limit','scope');
				$listings = cri('ContentScope')->getContent($paramsForScope,$viewObj->params);	
				$options['listingData'] = $listings;
				$detectType = "Listing";
			}
			$options['detectType'] = $detectType;
			$return = $viewObj->element("index_map", $options);
			if($return == "")
			{
				$return = false;
			}
			return $return;
		}
	}
?>